package com.chixing.day09.day09_Homework;

public class StringPssword {

    public static String encode(String password) {
        char[] c = password.toCharArray();
        char temp = c[0];
        for (int i = 0; i < password.length() - 1; i++) {
            c[i] = c[i + 1];
            c[i + 1] = temp;
            c[i] += 3;
        }
        c[password.length() - 1] += 3;
        return new String(c);
    }

    public static String decode(String password) {
        char[] c = password.toCharArray();
        char temp = c[password.length() - 1];
        for (int i = password.length() - 2; i >= 0; i--) {
            c[i + 1] = c[i];
        }
        c[0] = temp;
        for (int i = 0; i < password.length(); i++) {
            c[i] -= 3;
        }

        return new String(c);
    }


    public static void main(String[] args) {
        String pssword = "ABCHIJKLM";
        String result = encode(pssword);
        System.out.println("加密后: " + result);
        String result1 = decode(result);
        System.out.println("解密后: " + result1);

    }
}


